package com.shujia.spark.core

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

object Demo5FlatMap {
  def main(args: Array[String]): Unit = {
    val conf = new SparkConf()
    conf.setMaster("local")
    conf.setAppName("flatMap")

    val sc = new SparkContext(conf)

    /**
     * flatMap： 传入一行返回多行
     */

    val linesRDD: RDD[String] = sc.textFile("data/words")

    val wordsRDD: RDD[String] = linesRDD.flatMap((line: String) => {
      val array: Array[String] = line.split(",")
      //返回值可以是一个数组，集合，迭代器
      array.toList
    })

    wordsRDD.foreach(println)
  }

}
